package com.bxfy.rabbit.producer.service;

import com.bxfy.rabbit.producer.constant.BrokerMessageStatus;
import com.bxfy.rabbit.producer.entity.BrokerMessage;
import com.bxfy.rabbit.producer.mapper.BrokerMessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author caryguan
 * @version V1.0
 * @Package com.bxfy.rabbit.producer.service
 * @date 2020/10/2 18:49
 */
@Service
public class MessageStoreService {

    @Autowired
    private BrokerMessageMapper brokerMessageMapper;

    //当发送一条消息之前,副本落地然后发送消息
    public int insert(BrokerMessage brokerMessage) {
        return this.brokerMessageMapper.insert(brokerMessage);
    }

    public void success(String messageId) {
        this.brokerMessageMapper.changeBrokerMessageStatus(messageId, BrokerMessageStatus.SEND_OK.getCode(), new Date());

    }

    public void failure(String messageId) {
        this.brokerMessageMapper.changeBrokerMessageStatus(messageId, BrokerMessageStatus.SEND_FAIL.getCode(), new Date());

    }
}